﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace KTDS_IPBS_CLASSLIBRARY
{
    public class C_DBConnect
    {
        SqlConnection conn = new SqlConnection();
        //String conStr = @"server=10.225.22.44;Database=DB_IPBS_TEST;uid=sa;pwd=tpgns628";
        String conStr = @"server=10.225.22.47;Database=IPBS;uid=sa;pwd=new1234@";

        public String SelectGroupCode(String ipstr)
        {
            SqlCommand cmd = new SqlCommand();
            String groupcode = null;

            try
            {
                conn.ConnectionString = conStr;

                //실행 쿼리문
                //String query = "select groupcode from TB_IPINFO where = ipinfo'" + ipstr + "';";
                String query = "select parent_host from host_ip where ip='" + ipstr + "';";

                //쿼리 세팅
                cmd.CommandText = query;
                cmd.Connection = conn;

                conn.Open();

                //쿼리 실행결과 담기 - SqlDataReader 또는 SqlDataAdapter를 사용하면 된다.
                SqlDataReader reader = cmd.ExecuteReader();

                //결과값 출력하기
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        groupcode = reader[0].ToString();
                    }
                }

                conn.Close();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
            }

            return groupcode;
        }
    }
}
